#include <stdio.h>

int is_palindrome(unsigned long a){
	unsigned long MSB;
	for(MSB=1;MSB<a;MSB*=10);
	MSB/=10;
	
	while(MSB && (a/MSB)==(a%10))
	{
		a%=MSB;a/=10;
		MSB/=100;
	}
	if(MSB)	return 0;
	else return 1;
}

unsigned long reverse(unsigned long a){
	unsigned long res=0,MSB;
	for(MSB=1;MSB<a;MSB*=10);MSB/=10;
	while(a){
		res+=MSB*(a%10);
		MSB/=10;a/=10;
	}
	return res;
}

int reverse_add(long unsigned *a){
	unsigned long n=*a;int count=0;
	while(!is_palindrome(*a)){
		*a+=reverse(*a);
		count++;
	}
	return count;
}

int main(){
	long unsigned a;
	int N;
	int count;
	
	printf("%lu",reverse(123456));
	
	scanf("%d",&N);
	while(N--)
	{
		scanf("%lu",&a);
		printf("%d %lu\n",reverse_add(&a), a);
	}
	
	return 0;
}
